import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
import { DNavBar, DLookImages } from '@/components'
import './knowimages.scss'

const itemBgNone = require('../assets/car.png')
export default class KnowImages extends Component {

    constructor(props) {
        super(props)
        this.state = {
            knowUrl: [],
            companyurl: '',
            peopleright: '',
            peopleleft: '',
            doorurl: '',
            companycar: {
                itemStatus: false,
                itemUrl: ''
            }
        }
    }

    componentWillMount() {
        this.setState({
            knowUrl: [...JSON.parse(sessionStorage.getItem('knowurl'))]
        }, () => {
            sessionStorage.removeItem('knowurl')
        })
    }
    onLookHandle(url) {
        if (window.bridge) {
            let _images = [], i = 0
            _images.push(url)
            window.bridge.callHandler('previewPhoto', { "index": i, "images": _images }, function responseCallback() { })
        } else {
            this.setState({
                companycar: {
                    ...this.state.companycar,
                    itemStatus: true,
                    itemUrl: url
                }
            })
        }
    }

    onLookItem() {
        this.setState({
            companycar: {
                ...this.state.companycar,
                itemStatus: false,
                itemUrl: ''
            }
        })
    }
    getKnowUrl(cftype){
        let {knowUrl} = this.state
        let val = ''
        knowUrl.map(item=>{
            if(cftype === item.cfType){
                val =  item.cfFileUrl
            }
        })
        return val
    }
    render() {
        let {
            knowUrl,
            companycar
        } = this.state
        return (
            <View className='b_knowimages'>
                <DNavBar title='资料图片'></DNavBar>
                <View className='b_knowimages__box'>
                    <View className='b_knowimages__content'>
                        <View className='b_knowimages__item-text'>营业执照</View>
                        <View className='b_knowimages__item_box'>
                            <View className='b_knowimages__item'>
                                <Image src={this.getKnowUrl('1')} onClick={this.onLookHandle.bind(this, this.getKnowUrl('1'))} className='b_knowimages__item-img'></Image>
                            </View>
                        </View>
                    </View>
                </View>
                <View className='b_knowimages__content'>
                    <View className='b_knowimages__item-text'>法人身份证</View>
                    <View className='b_knowimages__item_box'>
                        <View className='b_knowimages__item'>
                            <Image src={this.getKnowUrl('2')} onClick={this.onLookHandle.bind(this, this.getKnowUrl('2'))} className='b_knowimages__item-img'></Image>
                        </View>
                        <View className='b_knowimages__item'>
                            <Image src={this.getKnowUrl('3')} onClick={this.onLookHandle.bind(this, this.getKnowUrl('3'))} className='b_knowimages__item-img'></Image>
                        </View>
                    </View>
                </View>
                <View className='b_knowimages__content'>
                    <View className='b_knowimages__item-text'>门店照片</View>
                    <View className='b_knowimages__item_box'>
                        <View className='b_knowimages__item'>
                            <Image src={this.getKnowUrl('4')} onClick={this.onLookHandle.bind(this, this.getKnowUrl('4'))} className='b_knowimages__item-img'></Image>
                        </View>
                    </View>
                </View>
                <DLookImages status={companycar.itemStatus} url={companycar.itemUrl} onLookHandle={this.onLookItem.bind(this)}></DLookImages>
            </View>
        )
    }
}
